<?php
	require ("../header.php");
	if ($ad_check<1)
	{
		header ("Location:../../login.php?action=0");
	}

	if (isset($_POST['ad_name'])) {
		$ad_name = $_POST['ad_name'];
		$check = 2;
	} else { $check = 3; }
	
	if (isset($_POST['ad_password'])) {	
		$ad_password = $_POST['ad_password'];
		$check = 2;
	} else { $check = 3; }
	
	if (isset($_POST['ad_no'])) {
		$ad_no = $_POST['ad_no'];
		$check = 2;
	} else { $check = 3; }
	
	if (isset($_POST['ad_department'])) {
		$ad_department = $_POST['ad_department'];
		$check = 2;
	} else { $check = 3; }
	
	if (isset($_POST['ad_permission'])) {
		$ad_permission = $_POST['ad_permission'];
		$check = 2;
	} else { $check = 3; }
	
	if ($check==2) {
	$sql_check_reg1= "SELECT ad_no FROM admin WHERE ad_no='$ad_no'";
	$pre_check=mysql_query($sql_check_reg1);
	$check=mysql_num_rows($pre_check);
	}
	
	if ($check==0) {	
		$sql_admin_reg = "INSERT INTO admin (ad_id,ad_name,ad_password,ad_no,ad_department,ad_permission) 
						  VALUES (NULL,'$ad_name',MD5('$ad_password'),'$ad_no','$ad_department','$ad_permission')";
		$result = mysql_query($sql_admin_reg);
		$sql_check_reg="SELECT * FROM admin WHERE ad_no='$ad_no'";
		$check_reg=mysql_query($sql_check_reg);
		$stat = mysql_num_rows($check_reg);
		if ($stat==1) {
			echo "<center><br><br><br><br><br><br>THANK YOU FOR REGISTERING.  YOUR REGISTRATION HAS BEEN SUCCESSFUL.</center><br><br><br><br><br><br><br><br>";
		} else {
			echo "<center><br><br><br><br><br><br>YOUR REGISTRATION FAILED.  PLEASE CHECK THIS PROBLEM WITH WEBMASTER.</CENTER><br><br><br><br><br><br><br><br>";
		}
	} elseif ($check==3) {
		echo "<center><br><br><br><br><br><br>YOUR REGISTRATION FAILED.  PLEASE FILL ALL FIELDS BEFORE SUBMIT.</CENTER><br><br><br><br><br><br><br><br>";
	} elseif ($check==1) {
		echo "<center><br><br><br><br><br><br>YOUR REGISTRATION FAILED.  USERNAME ALREADY EXIST.</CENTER><br><br><br><br><br><br><br><br>";
	}
	require ("../footer.php");
?>
	
	
